package simple.utils.processing;

/**
 * This relaying listener increases supplied Progress by 1 completed unit for every 1%.
 * Also appends msg + % (if msg is not null) to log
 * User: rehak
 * Date: 7/10/13
 * Time: 2:09 PM
 * To change this template use File | Settings | File Templates.
 */
public class RelayingPercentListener implements PercentListener {

    private final Progress p;
    private final String msg;

    public RelayingPercentListener(Progress p, String msg) {
        this.p = p;
        this.msg = msg;
    }

    @Override
    public void progressChanged(int percentComplete) {
        p.addCompleted(1);
        if(msg!=null) {
            p.appendLogMsg(msg+" %");
        }
    }
}
